//
//  indexViewController.swift
//  Swift夜间模式
//
//  Created by Hahn on 2018/11/2.
//  Copyright © 2018 今晚打老虎. All rights reserved.
//

import UIKit

class indexViewController: UIViewController {

    @IBOutlet weak var label: UILabel!
    @IBOutlet weak var state: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "首页"
        self.view.themeWithType(type: UIView.UIViewColorType.UIViewColorTypeNormal)
        //模式2
//        self.view.themeWithType(type: UIView.UIViewColorType.UIViewColorTypeNormal1)
        
        self.label.themeWithType(type1: UILabel.UILabelColorType.LabelColorBlack)
        //模式2
        //        self.label.themeWithType(type1: UILabel.UILabelColorType.LabelColorGray)
        
        self.state.themeWithType(type1: UILabel.UILabelColorType.LabelColorBlack)

    }
    
    /// 析构函数.类似于OC的 dealloc
    deinit {
        /// 移除通知
        NotificationCenter.default.removeObserver(self)
    }


    @IBAction func `switch`(_ sender: UISwitch) {
        if (sender.isOn) {
            
            //MARK : ?
            /*
             在Swift中，我们用var来定义变量，但Swfit中并不会自动给变量赋初始值。 所以如果使用未赋值的变量就会报错。
             "？”表示可选类型（Optionals） 就是将已存在的某种类型（结构体、枚举、类）定义为可选类型，表示该“新”类型的值可以为空nil
             “！”表示告诉系统，“我肯定这个可选属性有值，强制取出来用”（强制解包），但是，如果这个可选类型属性当时的值为nil，那么会crash
             */
            UIView.animate(withDuration: 0.3) {
                self.tabBarController?.viewControllers?[0].tabBarItem.image = UIImage(named: "cart-off")?.withRenderingMode(.alwaysOriginal);
                self.tabBarController?.viewControllers?[0].tabBarItem.selectedImage = UIImage(named: "cart-on")?.withRenderingMode(.alwaysOriginal);
                self.tabBarController?.viewControllers?[1].tabBarItem.image = UIImage(named: "order-off")?.withRenderingMode(.alwaysOriginal);
                self.tabBarController?.viewControllers?[1].tabBarItem.selectedImage = UIImage(named: "order-on")?.withRenderingMode(.alwaysOriginal);
                
                self.tabBarController?.viewControllers?[0].tabBarItem.title = "首页1"
                self.tabBarController?.viewControllers?[1].tabBarItem.title = "我的1"

                theme.Theme.appColor = 1;
                NotificationCenter.default.post(name: NSNotification.Name.init("changeColor"), object: nil)
                NotificationCenter.default.post(name: NSNotification.Name.init("changeColor1"), object: nil)
                NotificationCenter.default.post(name: NSNotification.Name.init("changeColor2"), object: nil)
                NotificationCenter.default.post(name: NSNotification.Name.init("changeColor3"), object: nil)
                self.view.themeWithType(type: UIView.UIViewColorType.UIViewColorTypeNormal)
                //模式2
                //        self.view.themeWithType(type: UIView.UIViewColorType.UIViewColorTypeNormal1)
                self.state.text = "夜间模式"

            }
        }else{
            UIView.animate(withDuration: 0.3) {
                self.tabBarController?.viewControllers?[0].tabBarItem.image = UIImage(named: "home-off")?.withRenderingMode(.alwaysOriginal);
                self.tabBarController?.viewControllers?[0].tabBarItem.selectedImage = UIImage(named: "home-on")?.withRenderingMode(.alwaysOriginal);
                self.tabBarController?.viewControllers?[1].tabBarItem.image = UIImage(named: "my-off")?.withRenderingMode(.alwaysOriginal);
                self.tabBarController?.viewControllers?[1].tabBarItem.selectedImage = UIImage(named: "my-on")?.withRenderingMode(.alwaysOriginal);
                self.tabBarController?.viewControllers?[0].tabBarItem.title = "首页"
                self.tabBarController?.viewControllers?[1].tabBarItem.title = "我的"

                theme.Theme.appColor = 0;
                NotificationCenter.default.post(name: NSNotification.Name.init("changeColor"), object: nil)
                NotificationCenter.default.post(name: NSNotification.Name.init("changeColor1"), object: nil)
                NotificationCenter.default.post(name: NSNotification.Name.init("changeColor2"), object: nil)
                NotificationCenter.default.post(name: NSNotification.Name.init("changeColor3"), object: nil)
                self.view.themeWithType(type: UIView.UIViewColorType.UIViewColorTypeNormal)
                //模式2
                //        self.view.themeWithType(type: UIView.UIViewColorType.UIViewColorTypeNormal1)
                self.state.text = "日间模式"
            }

        }
    }
    
}
